package org.afs.gescol.gwt.client.factory;

import org.afs.gescol.gwt.client.bundle.GescolResources;
import org.afs.gescol.gwt.client.controller.AppController;
import org.afs.gescol.gwt.client.controller.AppLayout;
import org.afs.gescol.gwt.client.i18n.AppMessages;
import org.afs.gescol.gwt.client.layout.AppLayoutImpl;
import org.afs.gescol.gwt.client.presenter.ConfigurationsPresenter;
import org.afs.gescol.gwt.client.presenter.ConfigurationsPresenter.ConfigurationsView;
import org.afs.gescol.gwt.client.presenter.ElevePresenter;
import org.afs.gescol.gwt.client.presenter.ElevePresenter.EleveView;
import org.afs.gescol.gwt.client.presenter.HomePresenter;
import org.afs.gescol.gwt.client.presenter.HomePresenter.HomeView;
import org.afs.gescol.gwt.client.util.ActionsKeysUtil;
import org.afs.gescol.gwt.client.util.SortKeysUtil;
import org.afs.gescol.gwt.client.view.ConfigurationsViewImpl;
import org.afs.gescol.gwt.client.view.ConfigurationsViewImpl.ConfigurationsViewBinder;
import org.afs.gescol.gwt.client.view.EleveViewImpl;
import org.afs.gescol.gwt.client.view.EleveViewImpl.EleveViewBinder;
import org.afs.gescol.gwt.client.view.HomeViewImpl;
import org.afs.gescol.gwt.client.view.HomeViewImpl.Binder;

import com.google.gwt.core.client.GWT;

/**
 * Application Client Factory.
 * @autor Kobla GBENYO (kobla.gbenyo@gmail.com)
 */
public final class AppClientFactory {

    public final static String SEARCH_TOKEN = "rech";

    public final static String CONFIG_TOKEN = "confs";

    public final static String EDT_TOKEN = "edt";

    public final static String NOTE_TOKEN = "note";

    public final static String STATS_TOKEN = "stats";
    
    private static HomePresenter homePresenter;

    private static ConfigurationsPresenter configurationsPresenter;
    
    private static HomeViewImpl homeView;

    private static ConfigurationsViewImpl configurationsView;

    private static AppController appController;

    private static AppLayout layout;

    private static AppMessages messages;

    private static GescolResources resources;

    private static Binder binder;

    private static EleveViewBinder eleveViewBinder;

    private static ConfigurationsViewBinder configurationsViewBinder;

    private static ActionsKeysUtil actionsKeysUtil;

    private static SortKeysUtil sortKeysUtil;

    private AppClientFactory() {
    }

    /**
     * Create and get an instance of ElevePresenter.
     * @return the ElevePresenter
     */
    public static ElevePresenter getElevePresenter() {
        return new ElevePresenter();
    }

    /**
     * Create and get an instance of HomePresenter.
     * @return the HomePresenter
     */
    public static HomePresenter getHomePresenter() {
        if (homePresenter == null) {
            homePresenter = GWT.create(HomePresenter.class);
        }
        return homePresenter;
    }

    /**
     * Create and get an instance of ConfigurationsPresenter.
     * @return the ConfigurationsPresenter
     */
    public static ConfigurationsPresenter getConfigurationsPresenter() {
        if (configurationsPresenter == null) {
            configurationsPresenter = GWT.create(ConfigurationsPresenter.class);
        }
        return configurationsPresenter;
    }

    /**
     * Create and get an instance of appController.
     * @return the controller
     */
    public static AppController getAppController() {
        if (appController == null) {
            appController = GWT.create(AppController.class);
        }
        return appController;
    }

    /**
     * Create and get an instance of layout.
     * @return the layout
     */
    public static AppLayout getLayout() {
        if (layout == null) {
            layout = GWT.create(AppLayoutImpl.class);
        }
        return layout;
    }

    /**
     * Create and get an instance of messages.
     * @return the messages
     */
    public static AppMessages getMessages() {
        if (messages == null) {
            messages = GWT.create(AppMessages.class);
        }
        return messages;
    }

    /**
     * Create and get an instance of resources.
     * @return the resources
     */
    public static GescolResources getResources() {
        if (resources == null) {
            resources = GWT.create(GescolResources.class);
        }
        return resources;
    }

    /**
     * Create and get an instance of binder.
     * @return the binder
     */
    public static Binder getBinder() {
        if (binder == null) {
            binder = GWT.create(Binder.class);
        }
        return binder;
    }

    /**
     * Create and get an instance of Eleve binder.
     * @return the binder
     */
    public static EleveViewBinder getEleveViewBinder() {
        if (eleveViewBinder == null) {
            eleveViewBinder = GWT.create(EleveViewBinder.class);
        }
        return eleveViewBinder;
    }

    public static ConfigurationsViewBinder getConfigurationsViewBinder() {
        if (configurationsViewBinder == null) {
            configurationsViewBinder = GWT.create(ConfigurationsViewBinder.class);
        }
        return configurationsViewBinder;
    }

    /**
     * Get SortKeysUtil.
     * @return SortKeysUtil
     */
    public static SortKeysUtil getSortKeysUtil() {
        if (sortKeysUtil == null) {
            sortKeysUtil = GWT.create(SortKeysUtil.class);
        }
        return sortKeysUtil;
    }

    /**
     * Get ActionsKeysUtil.
     * @return ActionsKeysUtil
     */
    public static ActionsKeysUtil getActionsKeysUtil() {
        if (actionsKeysUtil == null) {
            actionsKeysUtil = GWT.create(ActionsKeysUtil.class);
        }
        return actionsKeysUtil;
    }

    /**
     * Create a new instance of EleveView.
     * @return the EleveView
     */
    public static EleveView getEleveView() {
        return new EleveViewImpl();
    }

    /**
     * Create a new instance of HomeView.
     * @return the HomeView
     */
    public static HomeView getHomeView() {
        if (homeView == null) {
            homeView = GWT.create(HomeViewImpl.class);
        }
        return homeView;
    }

    /**
     * Create a new instance of ConfigurationsView.
     * @return the ConfigurationsView
     */
    public static ConfigurationsView getConfigurationsView() {
        if (configurationsView == null) {
            configurationsView = GWT.create(ConfigurationsViewImpl.class);
        }
        return configurationsView;
    }
}
